package com.ygqh.baby.model.ngmm;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.util.StringUtil;
import com.ygqh.baby.po.YgOrder;
import com.ygqh.baby.po.YgOrderDetail;

public class NgmmOrder extends YgOrder {
	
	private final BigDecimal zero = new BigDecimal("0.00");
	
	private Object extra;
	private String town;
	private String phone;
	private String sellerrRemark;
	private Double orderPrice;
	private Double postage;
	private String ngExpressCode;
	private String ngExpressNo;
	
	public NgmmOrder() {
		super.setProductPrice(zero);
		super.setManjianPrice(zero);
		super.setYouhuijuanPrice(zero);
		super.setGroupDisPrice(zero);
		super.setNewCustomDisPrice(zero);
		super.setPackDisPrice(zero);
		super.setBmdisPrice(zero);
		super.setAccountPrice(zero);
	}

	@Override
	@JSONField(name = "order_no")
	public void setOrderId(Long orderId) {
		super.setOrderId(orderId);
		super.setParentId(orderId);
	}

	@Override
	@JSONField(name = "order_time")
	public void setCreateTime(Date orderTime) {
		super.setCreateTime(orderTime);
	}
	
	@Override
	@JSONField(name = "payment_time")
	public void setPaidTime(Date paidTime) {
		super.setPaidTime(paidTime);
	}

	@Override
	@JSONField(name = "consignee")
	public void setReceiver(String receiver) {
		super.setReceiver(receiver);
	}

	@Override
	@JSONField(name = "province")
	public void setProvinceName(String provinceName) {
		super.setProvinceName(provinceName);
	}

	@Override
	@JSONField(name = "city")
	public void setCityName(String cityName) {
		super.setCityName(cityName);
	}

	@Override
	@JSONField(name = "area")
	public void setAreaName(String areaName) {
		super.setAreaName(areaName);
	}

	@Override
	@JSONField(name = "address")
	public void setAddress(String address) {
		super.setAddress((StringUtil.isBlank(this.town) ? "" : this.town) + address);
	}

	@Override
	@JSONField(name = "mobile")
	public void setTelPhone(String telPhone) {
		super.setTelPhone(StringUtil.isBlank(telPhone) ? this.phone : telPhone);
	}

	@Override
	@JSONField(name = "zipcode")
	public void setPostCode(String postCode) {
		super.setPostCode(postCode);
	}

	@JSONField(name = "detail")
	public void setExtra(Object extra) {
		this.extra = extra;
		List<YgOrderDetail> list = new ArrayList<YgOrderDetail>();
		if (extra != null) {
			String extraStr = JSONObject.toJSONString(extra);
			if (extra instanceof JSONObject) {
				list.add(JSONObject.parseObject(extraStr, NgmmOrderDetail.class));
			} else if (extra instanceof JSONArray) {
				List<NgmmOrderDetail> list2 = JSONArray.parseArray(JSONObject.toJSONString(extra), NgmmOrderDetail.class);
				for (NgmmOrderDetail ngmmOrderDetail : list2) {
					list.add(ngmmOrderDetail);
				}
			}
		}
		super.setOrderDetail(list);
	}

	public String getTown() {
		return town;
	}

	@JSONField(name = "town")
	public void setTown(String town) {
		this.town = town;
	}

	public String getPhone() {
		return phone;
	}

	@JSONField(name = "phone")
	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getSellerrRemark() {
		return sellerrRemark;
	}

	@JSONField(name = "seller_remark")
	public void setSellerrRemark(String sellerrRemark) {
		this.sellerrRemark = sellerrRemark;
		super.setUserRemark(sellerrRemark);
	}

	public Double getOrderPrice() {
		return orderPrice;
	}

	@JSONField(name = "order_price")
	public void setOrderPrice(Double orderPrice) {
		this.orderPrice = orderPrice;
		super.setTotalPrice(zero.add(BigDecimal.valueOf(orderPrice)));
	}

	public BigDecimal getZero() {
		return zero;
	}

	public Object getExtra() {
		return extra;
	}


	public Double getPostage() {
		return postage;
	}

	@JSONField(name = "postage")
	public void setPostage(Double postage) {
		this.postage = postage;
		super.setExpressPrice(zero.add(BigDecimal.valueOf(postage)));
	}
	
	public String getNgExpressCode() {
		return ngExpressCode;
	}

	@JSONField(name = "express_code")
	public void setNgExpressCode(String ngExpressCode) {
		this.ngExpressCode = ngExpressCode;
	}

	public String getNgExpressNo() {
		return ngExpressNo;
	}

	@JSONField(name = "express_no")
	public void setNgExpressNo(String ngExpressNo) {
		this.ngExpressNo = ngExpressNo;
	}

	@Override
	public String toString() {
		return "NgmmOrder [extra=" + extra + ", town=" + town + ", phone=" + phone + ", " + super.toString() + "]";
	}

}
